package com.solidtrust.repository;

import java.util.Date;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.solidtrust.entity.Che168;

public interface Che168Repository extends JpaRepository<Che168, Long>{

	Page<Che168> findByBrandAndModelAndBuildAndScrapedDateGreaterThanAndMileageBetween(
				Pageable pageable, String brand, String model, String build, Date from, 
				Integer mileageStart, Integer mileageEnd);
	
	@Query("select max(c.soldPrice), min(c.soldPrice), avg(c.soldPrice), count(c) from Che168 c where c.brand = ? and c.model = ? and c.build = ? and c.scrapedDate > ? and c.mileage between ? and ?")
	Object[] aggregate(String brand, String model, String build, Date from, 
				Integer mileageStart, Integer mileageEnd);
}
